package Exercise;

public class RegexExe2 {
    public static void main(String[] args) {
        //验证用户名  4-16位 字母数字 下划线
        String test1 = "ach_1736IN";
        boolean flag;
        flag=checkUserName(test1);
        System.out.println(flag);

        String test2="130624202402292091";
        flag=checkDifficultId(test2);
        System.out.println(flag);

    }

    public static boolean checkUserName(String username) {
        String str = "\\w{4,16}";
        return username.matches(str);
    }

    public static boolean checkSimpleId(String Id) {
        String str = "[0-9]{17}[0-9xX]";
        return Id.matches(str);
    }
    public static boolean checkDifficultId(String Id){
        //前六位是省市区 第一位不能是0后五位任意数字


        String str="[1-9]" +
                "\\d{5}" +

                "(18|19|20)\\d{2}"+
                "((0[13578](0[1-9]|[12][0-9]|3[01]))" +
                "|(0[469](0[1-9]|[12][0-9]|30))" +
                "|(02(0[1-9]|[12][0-9]))" +
                "|(1[02]([0][1-9]|[12][0-9]|3[01]))" +
                "|(11(0[1-9]|[12][0-9]|30) ))" +
//                "(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])"+
                "\\d{3}" +
                "[\\dxX]";
        return Id.matches(str);
    }
}
